package leecode

func buildArray(target []int, n int) (result []string) {
	stack := make([]int, 0)
	index := 1
	i := 0
	for len(stack) <= len(target) && index <= n && i < len(target) {
		//push 入栈操作
		stack = append(stack, index)
		result = append(result, "Push")
		//入栈之后,判断该元素是否在栈中
		if index == target[i] {
			i++
		} else {
			//如果不等于 将当前元素推出
			stack = stack[:len(stack)-1]
			result = append(result, "Pop")
		}
		index++
	}
	return
}
